
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.ShopStore;
import com.shop.cloud.mall.admin.service.ShopStoreService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 店铺门店
 *
 * @author
 * @date 2023-05-17 16:46:55
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/shopstore")
@Tag(description = "shopstore", name = "店铺门店管理")
public class ShopStoreController {

    private final ShopStoreService shopStoreService;

    /**
     * 店铺门店分页列表
     * @param page 分页对象
     * @param shopStore 店铺门店
     * @return
     */
    @Operation(summary = "店铺门店分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:shopstore:index')")
    public R getPage(Page page, ShopStore shopStore) {
        return R.ok(shopStoreService.page(page, Wrappers.query(shopStore)));
    }

    /**
     * 店铺门店查询
     * @param id
     * @return R
     */
    @Operation(summary = "店铺门店查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:shopstore:get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(shopStoreService.getById(id));
    }

    /**
     * 店铺门店新增
     * @param shopStore 店铺门店
     * @return R
     */
    @Operation(summary = "店铺门店新增")
    @SysLog("新增店铺门店")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:shopstore:add')")
    public R save(@RequestBody ShopStore shopStore) {
        return R.ok(shopStoreService.save(shopStore));
    }

    /**
     * 店铺门店修改
     * @param shopStore 店铺门店
     * @return R
     */
    @Operation(summary = "店铺门店修改")
    @SysLog("修改店铺门店")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:shopstore:edit')")
    public R updateById(@RequestBody ShopStore shopStore) {
        return R.ok(shopStoreService.updateById(shopStore));
    }

    /**
     * 店铺门店删除
     * @param id
     * @return R
     */
    @Operation(summary = "店铺门店删除")
    @SysLog("删除店铺门店")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:shopstore:del')")
    public R removeById(@PathVariable String id) {
        return R.ok(shopStoreService.removeById(id));
    }

}
